package com.xiaoshuidi.cloud.module.member.controller.app.invite;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.annotations.PreAuthenticated;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteActivityConfigVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteActivityLogVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteLogPageVo;
import com.xiaoshuidi.cloud.module.member.controller.app.invite.vo.AddInviteLogVo;
import com.xiaoshuidi.cloud.module.member.controller.app.invite.vo.InviteSummaryVo;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.invite.InviteActivityConfigService;
import com.xiaoshuidi.cloud.module.member.service.invite.InviteActivityLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Leo Li
 * @version generator
 * @description 租客银行卡
 * @date 2023-05-19 17:20:47
 */
@Tag(name = "租客APP - 邀请活动")
@RestController
@RequestMapping(ApiConstants.NAME + "/invite-activity")
@Validated
@Slf4j
public class MemberUserInviteActivityController {

    @Resource
    InviteActivityLogService inviteActivityLogService;
    @Resource
    InviteActivityConfigService inviteActivityConfigService;

    @GetMapping("/invite-summary")
    @Operation(summary = "邀请活动汇总")
    @PreAuthenticated
    public CommonResult<InviteSummaryVo> userInviteSummary() {
        InviteSummaryVo vo = inviteActivityLogService.getInviteSummary(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(vo);
    }

    @GetMapping("/invite-config")
    @Operation(summary = "邀请活动配置")
    public CommonResult<InviteActivityConfigVo> getInviteConfig() {
        InviteActivityConfigVo config = inviteActivityConfigService.getValidInviteConfig();
        if (ObjectUtils.isEmpty(config)) {
            return CommonResult.success(new InviteActivityConfigVo());
        }
        return CommonResult.success(config);
    }

    @PostMapping("/invite-logs")
    @Operation(summary = "邀请列表")
    @PreAuthenticated
    public CommonResult<PageResult<InviteActivityLogVo>> userInviteLogs(InviteLogPageVo form) {
        form.setAccountId(SecurityFrameworkUtils.getLoginUserId());
        PageResult<InviteActivityLogVo> page = inviteActivityLogService.getUserInviteActivityLogs(form);
        return CommonResult.success(page);
    }

    @PostMapping("/add-invite-log")
    @Operation(summary = "添加邀请记录")
    public CommonResult<Boolean> addInviteLog(@RequestBody AddInviteLogVo form) throws Exception {
        inviteActivityLogService.addUserInviteLog(form);
        return CommonResult.success(Boolean.TRUE);
    }
}

